home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDScan.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.6 KB  |  179 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDScan - An XFCN to scan absolute minute, second, block
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/10/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDScan.c
  11.     link -sn Main=CDScan -sn STDIO=CDScan ∂
  12.          -sn INTENV=CDScan -rt XFCN=42 ∂
  13.          -m CDSCAN CDScan.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. void    ExtractBCD(char *, short *);
  28. OSErr    AScan(short, short, short, short, short);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDScan
  36.  *
  37.  *  Purpose:        Scan absolute minute, second and block
  38.  *
  39.  *  Returns:        result of driver call to Scan
  40.  *                    normally 0, but could have parameter error or
  41.  *                    other error if non-existent block is specified
  42.  *
  43.  *  Side Effects:
  44.  *
  45.  *  Description:    We need four parameters:
  46.  *                    1) the direction - 0 is forward, 1 is reverse
  47.  *                    2) the minute
  48.  *                    3) the second
  49.  *                    4) the block
  50.  *                    Get the famous global ioRefNum.
  51.  *                    Extract the minute, second and block and start
  52.  *                    Scanning at that point.
  53.  *
  54.  ************************************************************************/
  55. pascal void
  56. CDScan(paramPtr)
  57. XCmdBlockPtr    paramPtr;
  58. {
  59.     Str31    returnString;
  60.     OSErr    result;
  61.     short    minute;
  62.     short    second;
  63.     short    block;
  64.     short    ioRefNum;
  65.     Handle    refHandle;
  66.     short    direction;
  67.     
  68.     /* Must be four parameters */
  69.     if ((paramPtr->paramCount) != 4)
  70.     {
  71.         /* Report error in parameters by returning -1 */
  72.         NumToStr(paramPtr, (long) -1, &returnString);
  73.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  74.         return;
  75.     }
  76.     
  77.     /* Get the global ioRefNum and convert it. */
  78.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  79.     ioRefNum = atoi(*(refHandle));
  80.     DisposHandle(refHandle);
  81.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  82.     
  83.     /* First param is direction.  Convert it to a short */
  84.     direction = atoi(*(paramPtr->params[0]));
  85.  
  86.     /* Second param is minute.  Convert it to a BCD number */
  87.     ExtractBCD((char *)*(paramPtr->params[1]), &minute);
  88.     
  89.     /* Third param is second.  Convert it to a BCD number */
  90.     ExtractBCD((char *)*(paramPtr->params[2]), &second);
  91.     
  92.     /* Fourth param is block.  Convert it to a BCD number */
  93.     ExtractBCD((char *)*(paramPtr->params[3]), &block);
  94.     
  95.     result = AScan(ioRefNum, direction, minute, second, block);
  96.     
  97.     /* Convert result to string & return it */
  98.     NumToStr(paramPtr, (long) result, &returnString);
  99.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  100. }
  101.  
  102. /************************************************************************
  103.  *
  104.  *  Function:        ExtractBCD
  105.  *
  106.  *  Purpose:        Extract number in BCD from CString
  107.  *
  108.  *  Returns:        nothing
  109.  *
  110.  *  Side Effects:    *track gets a new BCD value
  111.  *
  112.  *  Description:    Extract number in BCD from Cstring "name".
  113.  *                    "name" is always of the form "XX", where XX
  114.  *                    ranges from "1"  to "99"
  115.  *
  116.  ************************************************************************/
  117. void
  118. ExtractBCD(name, number)
  119. char        *name;
  120. short        *number;
  121. {
  122.     short    t;
  123.         
  124.     t = 0;
  125.     while (*name != 0)
  126.     {
  127.         t *= 16;
  128.         t += *name - '0';
  129.         name++;
  130.     }
  131.     
  132.     *number = t;    
  133. }
  134.  
  135. /************************************************************************
  136.  *
  137.  *  Function:        AScan
  138.  *
  139.  *  Purpose:        start Scaning at an absolute minute, second, block
  140.  *
  141.  *  Returns:        OSErr.  Probably either
  142.  *                        noErr        everything's hunky-dory!
  143.  *                        paramErr    you messed up the call somehow.
  144.  *
  145.  *  Side Effects:    starts Scan.  By default, this will Scan until the
  146.  *                    end of the disc.
  147.  *
  148.  *  Description:    pass in the absolute minute, second and block in BCD.
  149.  *
  150.  ************************************************************************/
  151. OSErr
  152. AScan(refNum, direction, minute, second, block)
  153. short    refNum;
  154. short    direction;
  155. short    minute;
  156. short    second;
  157. short    block;
  158. {
  159.     CDPlayParam    myPB;
  160.     
  161.     myPB.ioCompletion = 0;
  162.     myPB.ioNamePtr = (char *) 0;
  163.     myPB.ioVRefNum = 1;
  164.     myPB.ioCRefNum = refNum;
  165.     myPB.csCode = ASCAN;
  166.     
  167.     myPB.addrFormat = AMSFADDR;
  168.     myPB.unused = 0;            /* must be in BCD */
  169.     myPB.minute = (char) minute;    /* must be in BCD */
  170.     myPB.second = (char) second;    /* must be in BCD */
  171.     myPB.block = (char) block;    /* must be in BCD */
  172.     myPB.stopAddress = direction;
  173.     return (PBControl(&myPB, false));
  174. }
  175.  
  176.  
  177. /* C routines for HyperCard callbacks */
  178. #include <XCmdGlue.inc.c>
  179.